package cn.tedu.baidashi.controller;

import cn.tedu.baidashi.model.Customer;
import cn.tedu.baidashi.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2022-02-12
 */
@RestController
//requestMapping请求的getAll方法和得到我的顾客对象
@RequestMapping("/portal/customer")
public class CustomerController {
    @Autowired
    private ICustomerService customerService;
    @GetMapping("/get")
    public List<Customer> getAll(){
        List<Customer> customers=customerService.getAll();
        return customers;
    }
    //以下是修改的第三个地方
    @GetMapping("/getCurrentVo")
    public String me(
            @AuthenticationPrincipal UserDetails user){
//        CustomerVo customervo=customerService
//                .getCustomerVo(user.getUsername());
        System.out.println(user.getUsername());
        return user.getUsername();
    }
}
